<meta charset="UTF-8">
<?php

require ('./lib/init.php');//初始化
// 判断用户是否登录
if (!acc()) {
    header('Location:login.php');
}
$cat_id = $_GET['cat_id'];
//检测栏目是否合法
if (!is_numeric($cat_id)){
    error ('栏目不合法','javascript:history.back(-1)');
    exit();
}
//检测栏目是否存在
$sql = "select count(*) from cat where cat_id = $cat_id";
$rs = mQuery($sql);
if (mysqli_fetch_row($rs)[0] == 0){
    error ('栏目不存在','javascript:history.back(-1)');
    exit();
}
//检测栏目是否存在文章
$sql = "select count(*) from art where cat_id = $cat_id";
$rs =  mQuery($sql);
$rs = mysqli_fetch_row($rs);
if ($rs[0] != 0){
    error ('栏目下存在文章','javascript:history.back(-1)');
    exit();
}

//检测完毕 删除分类
$sql = "delete from cat where cat_id = $cat_id";
if (!mQuery($sql)){
    error ('分类删除失败','catlist.php');
}else{
    succ ('分类删除成功','catlist.php');
}
?>
